﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlayListSet.Entity
{
    public class AudioInfo
    {
        public string ProductName { set; get; }
        public string ManufacturerGuid { set; get; }
        public string ShowStr
        {
            get
            {
                return ToStr();
            }
        }
        public string ToStr()
        {
            return ProductName + "|" + ManufacturerGuid;
        }
        public static  AudioInfo GetAudio(string str)
        {
            if(str == null || str.Trim()=="") return new AudioInfo { ProductName = "默认设备", ManufacturerGuid = "" };
            string[] arr = str.Split('|');
            if(arr.Length==2)
                return new AudioInfo { ProductName = arr[0], ManufacturerGuid = arr[1] };
            return new AudioInfo { ProductName = "默认设备", ManufacturerGuid = "" };
        }
        public static List<AudioInfo> GetAudioInfos()
        {
            List < AudioInfo > audioInfos = new List < AudioInfo >();
            for (int i = 0; i < NAudio.Wave.WaveOut.DeviceCount; i++)
            {
                var d = NAudio.Wave.WaveOut.GetCapabilities(i);
                audioInfos.Add(new AudioInfo {  ProductName= d.ProductName ,
                    ManufacturerGuid=d.ManufacturerGuid.ToString()});
            }
            return audioInfos;
        }

        public static int GetAudioOutIndex(string str)
        {
            var info = GetAudio(str);
            if (info.ProductName == "默认设备")
            {
                return -1;
            }
            for (int i = 0; i < NAudio.Wave.WaveOut.DeviceCount; i++)
            {
                var d = NAudio.Wave.WaveOut.GetCapabilities(i);
                if(d.ProductGuid.ToString()==info.ManufacturerGuid.ToString())
                {
                    return i;
                }
            }
            return -2;

        }

    }
}
